package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsPageReqDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import com.heima.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news/page")
    public PageResult<WmNewsResultDTO> findByPage(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findByPage(dto);
    }

    /**
     * 新增 修改 提交审核
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        wmNewsService.submit(dto);
        return  ResponseResult.ok();
    }
    @GetMapping("/api/v1/news/one/{id}")
    public ResponseResult<WmNewsResultDTO> findOneNews(@PathVariable(name = "id")Integer wmNewsId){
        return ResponseResult.ok(wmNewsService.findOneNews(wmNewsId));
    }

    /***
     * 上下架操作
     * @param wmNews
     * @return
     */
    @PutMapping("/api/v1/news/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNews wmNews){
        wmNewsService.downOrUp(wmNews);
        return ResponseResult.ok();
    }
}
